﻿using FluentMigrator;

namespace Budget.DataBase.Migrations
{
    [Migration(8)]
    public class M008_CreateRelationBetweenIncomeTypeAndIncomeOrder : Migration
    {
        private const string FK_COLUMN_NAME = "IncomeTypeId",
                             FK_NAME = "FK_IncomeOrders_IncomeType",
                             PRIMARY_TABLE_NAME = "IncomeTypes",
                             RELATED_TABLE_NAME = "IncomeOrders";

        public override void Up()
        {
            Create.Column(FK_COLUMN_NAME).OnTable(RELATED_TABLE_NAME).AsInt32().NotNullable().WithDefaultValue(0);

            Create.ForeignKey(FK_NAME)
                .FromTable(RELATED_TABLE_NAME)
                .ForeignColumn(FK_COLUMN_NAME)
                .ToTable(PRIMARY_TABLE_NAME)
                .PrimaryColumn("Id");
        }

        public override void Down()
        {
            Delete.ForeignKey(FK_NAME).OnTable(RELATED_TABLE_NAME);

            Delete.Column(FK_COLUMN_NAME).FromTable(RELATED_TABLE_NAME);
        }
    }
}